<template>
	<view>
		<block v-for="(item,index) in topicList" :key="index">
			<view class="topic-item" @click="chooseTopic(item)">
				<u-image :customStyle="{marginRight:'20rpx'}" width="120rpx" height="120rpx" radius="10rpx"
					:src="item.cover_image"></u-image>
				<view class="center">
					<view>{{item.name.substring(0,10)}}</view>
					<view class="desc">{{item.description|replace}}</view>
				</view>
				<view class="count-box">
					<text>{{item.user_num}}圈友</text>
					<text>{{item.post_num}}动态</text>
				</view>
			</view>
		</block>
		<!-- 加载状态 -->
		<block v-if="loadStatus != 'none'">
			<block v-if="topicList.length > 0">
				<view style="margin: 30rpx;">
					<u-loadmore :status="loadStatus" loadingIcon='semicircle' :iconColor="themesColor" />
				</view>
			</block>
			<block v-else>
				<u-empty text="暂无相关圈子" mode="favor" icon="/static/empty.png"></u-empty>
			</block>
		</block>
	</view>
</template>

<script>
	import {
		themesColor
	} from '@/uni.scss';
	export default {
		data() {
			return {
				themesColor,
				topicList: [],
				loadStatus: "nomore"
			};
		},
		filters: {
			replace(str) {
				str = str.replace(/\n/g, '');
				return str.substring(0, 40);
			}
		},
		onLoad() {
			this.getTopicList()
		},
		methods: {
			getTopicList() {
				this.$H.get("topic/currentUserJoinTopic").then(res => {
					this.topicList = res.result
				})
			},
			chooseTopic(data) {
				// 获取页面栈
				const pages = getCurrentPages();
				// 判断是否有上一页
				if (pages.length > 1) {
					// 获取上一页实例
					const prevPage = pages[pages.length - 2];
					prevPage.$vm.topicId = data.id;
					prevPage.$vm.topicName = data.name;
					prevPage.$vm.form.class_id = data.class_id;

					// 返回上一页
					uni.navigateBack();
				}
			}
		}
	}
</script>

<style>
	page {
		background-color: #f5f5f5;
	}
</style>
<style lang="scss" scoped>
	.topic-item {
		display: flex;
		align-items: center;
		background-color: #fff;
		padding: 30rpx;
		border-bottom: 1px solid #f5f5f5;

		.center {
			flex: 1;

			.desc {
				font-size: 20rpx;
				color: #999;
			}
		}

		.count-box {
			display: flex;
			flex-direction: column;
			font-size: 20rpx;
			color: #999;
			margin-left: 20rpx;
		}
	}
</style>